using System.Collections;
using System.Collections.Generic;
using DDA;
using UnityEngine;
using YDExtendTool.Scripts;

public class DDALogic : DDACondition
{
    public override int NextNodeMaxNum => 2;

    public override bool CanConnect(TreeNodeBase treeNodeBase)
    {
        return base.CanConnect(treeNodeBase) && treeNodeBase is DDACondition;
    }
}

/// <summary>
/// 逻辑与
/// </summary>
public class DDALogicAnd : DDALogic
{
    public override bool Invoke()
    {
        base.Invoke();
        var result = true;
        for (int i = 0; i < ChildNodes.Count; i++)
        {
            if (ChildNodes[i] is DDACondition ddaCondition)
            {
                result &= ddaCondition.Invoke();
                if (!result) return false;
            }
        }
        return true;
    }
}

/// <summary>
/// 逻辑或
/// </summary>
public class DDALogicOr : DDALogic
{
    public override bool Invoke()
    {
        base.Invoke();
        if (ChildNodes.Count == 0) return true;
        var result = false;
        for (int i = 0; i < ChildNodes.Count; i++)
        {
            if (ChildNodes[i] is DDACondition ddaCondition)
            {
                result |= ddaCondition.Invoke();
                if (result) return true;
            }
        }
        return false;
    }
}

/// <summary>
/// 逻辑非
/// </summary>
public class DDALogicNot : DDALogic
{
    public override int NextNodeMaxNum => 1;

    public override bool Invoke()
    {
        base.Invoke();
        if (ChildNodes.Count !=1) return true;
        return ! ChildNodes[0].Invoke();
    }
}



